package ${packageName}

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.powermock.api.mockito.PowerMockito.*;

// todo 动态导入
<#list importList as importClassSimpleName>
import ${importClassSimpleName};
</#list>

@RunWith(PowerRunner.class)
public class ${testFileSimpleName} {

    @InjectMocks
    private ${classSimpleName} ${varName};  // todo 应考虑spy代理、抽象类继承

    // mock成员变量
    <#list allTestFields as field>
    @Mock
    ${field.signatureClassSimpleName} ${field.name};
    </#list>

    @Before
    public void setUp() throws Exception {
        // todo mockStatic方法
    }

    // 单元测试方法
    <#list allTestMethods as method>
    @Test
    public void ${method.name}Test${method.index}() throws Exception {
        // 局部变量mock
        <#list method.variableTypeList as varItem>
        <#if varItem.type == 'invoke_new' || varItem.type == 'invoke_return'>
        ${varItem.signatureSimpleName} ${varItem.name}Mock = mock(${varItem.descriptorSimpleName}.class);
        </#if>
        </#list>
        <#list method.whenNewMethods as varItem>
        whenNew(${varItem.ownerSimpleName}.class).withNoArguments().thenReturn(${varItem.ownerVarName}Mock);
        </#list>
        // invoke 存根

        // 调用方法
    }
    </#list>
}